<?php
namespace Home\Controller;
use Think\Controller;
class OpenningController extends Controller {
    public function openning($sid=0,$p=1){
       //取产品分类
		$prowedding=M(proopenning);//选择数据表
		$result=$proopenning->where("pid=0")->order("o asc")->limit(0,6)->select();
		$this->assign("type_info",$result);
		

		//分页获取产品的信息
		$sid = intval($sid);    //分类id
		$p = intval($p)>0?$p:1;//当前页码
		
		$openning = M('openning');//选择数据表
		$pagesize = 5;#每页数量
		$offset = $pagesize*($p-1);//计算记录偏移量
		$prefix = C('DB_PREFIX');
		if($sid){
			$where = "{$prefix}openning.sid=$sid";
		}else{
			$where = '';
		}
		$count = $openning->where($where)->count();
		$list  = $openning->field("{$prefix}openning.*,{$prefix}proopenning.name")->where($where)->order("{$prefix}openning.pid desc")->join("{$prefix}proopenning ON {$prefix}proopenning.id = {$prefix}openning.sid")->limit($offset.','.$pagesize)->select();
		
		$page	=	new \Think\Page($count,$pagesize); 
		$page = $page->show();
        $this->assign('prolist',$list);	
        $this->assign('page',$page);
        $this->display();
    }
}